package com.offer;

import com.bean.TreeNode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @Author: huangzhigao
 * @Date: 2023/3/4 18:57
 */
public class offer38 {
    private HashSet<String> res = new HashSet<>();

    public String[] permutation(String s) {
        dfs(s.toCharArray(), new StringBuilder(), new boolean[s.length()]);

        String[] strings = new String[res.size()];
        int index = 0;
        for(String r:res){
            strings[index++] = r;
        }
        return strings;
    }
    public boolean isBalanced(TreeNode root) {
        if(root == null){
            return true;
        }

        return Math.abs(length(root.left)-length(root.right))<2;
    }

    public int length(TreeNode root){
        if(root == null){
            return 0;
        }

        return Math.max(length(root.left),length(root.right))+1;
    }


    public void dfs(char[] array, StringBuilder stringBuilder, boolean[] visited) {
        if (stringBuilder.length() == array.length) {
            res.add(stringBuilder.toString());
            return;
        }

        for (int i = 0; i < array.length; i++) {
            if (!visited[i]) {
                visited[i] = true;
                stringBuilder.append(array[i]);
                dfs(array, stringBuilder, visited);
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
                visited[i] = false;
            }
        }
    }

    public static void main(String[] args) {
        offer38 offer38 = new offer38();
        offer38.permutation("abc");

    }
}
